package com.yeban.javase.day04.test03;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/12
 */
public class Computer {

    // 三种存储数据交换
    public void dataExchange(StorageDevice storageDevice) {
        System.out.println("---------- 开始数据交换 ----------");
        storageDevice.read();
        storageDevice.write();

        if(storageDevice instanceof MP3Player) {
            ((MP3Player)storageDevice).playMusic();
        }
        System.out.println("---------- 数据交换结束 ----------\n");
    }

    public static void main(String[] args) {

        // 创建计算机对象
        Computer c = new Computer();

        // 创建各种存储设备
        StorageDevice udisk = new Udisk();
        StorageDevice hardDisk = new MobileHardDisk();
        MP3Player mp3 = new MP3Player();

        // 计算机和不同设备进行数据交换
        c.dataExchange(udisk);
        c.dataExchange(hardDisk);
        c.dataExchange(mp3);

    }

}
